package me.zhengjie.modules.ImgIntroduction.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.ImgIntroduction.domain.ImageIntroduction;
import me.zhengjie.modules.ImgIntroduction.service.ImageIntroductionService;
import me.zhengjie.modules.ImgIntroduction.service.dto.ImageIntroductionDto;
import me.zhengjie.modules.ImgIntroduction.service.dto.ImageIntroductionQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author TianI
* @date 2022-01-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "ImgIntroductionController管理")
@RequestMapping("/api/imageIntroduction")
public class ImageIntroductionController {

    private final ImageIntroductionService imageIntroductionService;

    @GetMapping
    @Log("查询ImgIntroductionController")
    @ApiOperation("查询ImgIntroductionController")
    @PreAuthorize("@el.check('imageIntroduction:list')")
    public ResponseEntity query(ImageIntroductionQueryParam query, Pageable pageable){
        return new ResponseEntity<>(imageIntroductionService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增ImgIntroductionController")
    @ApiOperation("新增ImgIntroductionController")
    @PreAuthorize("@el.check('imageIntroduction:add')")
    public ResponseEntity create(@Validated @RequestBody ImageIntroductionDto resources){
        return new ResponseEntity<>(imageIntroductionService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改ImgIntroductionController")
    @ApiOperation("修改ImgIntroductionController")
    @PreAuthorize("@el.check('imageIntroduction:edit')")
    public ResponseEntity update(@Validated @RequestBody ImageIntroductionDto resources){
        imageIntroductionService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除ImgIntroductionController")
    @ApiOperation("删除ImgIntroductionController")
    @PreAuthorize("@el.check('imageIntroduction:del')")
    public ResponseEntity delete(@RequestBody Set<Long> ids) {
        imageIntroductionService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出ImgIntroductionController")
    @ApiOperation("导出ImgIntroductionController")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('imageIntroduction:list')")
    public void download(HttpServletResponse response, ImageIntroductionQueryParam query) throws IOException {
        imageIntroductionService.download(imageIntroductionService.queryAll(query), response);
    }*/

}
